﻿using System.Collections;
using System.Collections.Generic;
using System;
using System.Text;
using DAL;
using BLL;
using System.IO;
using System.Data;
using System.Xml;
using System.Web.Security;
using System.Security.Cryptography;
using System.Net;
using System.Web;

namespace Web.Old_App_Code
{

    /// <summary>
    ///PaypalConfig 的摘要说明
    /// </summary>
    public class PaypalConfig
    {
        // Fields
        protected DataEncryption de = new DataEncryption();
        public string pass;
        public string sign;
        public string user;

        // Methods
        public PaypalConfig()
        {
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(this.GetFilePath());
                XmlNodeList childNodes = document.SelectSingleNode("paymentMethod").ChildNodes;
                foreach (XmlNode node in childNodes)
                {
                    XmlElement element = (XmlElement)node;
                    if (element.GetAttribute("id") == "2")
                    {
                        this.user = element.GetAttribute("seller_email");
                        this.pass = element.GetAttribute("key");
                        this.sign = element.GetAttribute("partner");
                        return;
                    }
                }
            }
            catch
            {
            }
        }

        protected string GetFilePath()
        {
            return HttpContext.Current.Server.MapPath("/xml/payment.xml");
        }

        public void Update()
        {
            XmlDocument document = new XmlDocument();
            document.Load(this.GetFilePath());
            XmlNode documentElement = document.DocumentElement;
            documentElement["user"].InnerText = this.user;
            documentElement["pass"].InnerText = this.pass;
            documentElement["sign"].InnerText = this.sign;
            document.Save(this.GetFilePath());
        }

    }
}